package com.vidyu.businesslayer.businessentities;

import com.vidyu.businesslayer.businesscomponents.Constants;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 * User: eyalsa
 * Date: 3/31/13
 * Time: 7:47 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "msgs")

@NamedQueries({
        @NamedQuery(
                name = "getAllMsgByTime",
                query = "FROM com.vidyu.businesslayer.businessentities.Msg as msg WHERE  msg.fromId = ? ORDER BY msg.time DESC"
        )})
public class Msg implements Serializable {

    private static final long serialVersionUID = 3197073386701729397L;
    private long id = Constants.NON_VALID_ID;
    private long fromId;
    private long toId;
    private long time;
    private String msg;
    private MsgStatus msgStatus = MsgStatus.NEW;

    public enum MsgStatus {
        NONE(0), NEW(1), READ(2), DELETED_BY_SENDER(3),  DELETED_BY_RECEIVER(4),  DELETED_BY_BOTH_SIDES(5);
        private int value;

        private MsgStatus(int value) {
            this.value = value;
        }
    }

    public Msg() {
    }

    public Msg(long fromId, long toId, String msg) {
        this.fromId = fromId;
        this.toId = toId;
        this.msg = msg;
        this.time = System.currentTimeMillis();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "msg_id", nullable = false, length = 11)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getFromId() {
        return fromId;
    }

    public void setFromId(long fromId) {
        this.fromId = fromId;
    }

    public long getToId() {
        return toId;
    }

    public void setToId(long toId) {
        this.toId = toId;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Enumerated(EnumType.ORDINAL)
    public MsgStatus getMsgStatus() {
        return msgStatus;
    }

    public void setMsgStatus(MsgStatus msgStatus) {
        this.msgStatus = msgStatus;
    }
}
